class SessionsController < ApplicationController
  # 引入会话帮助器
  include SessionsHelper

  # GET /login
  def new
  end

  # POST /login
  # 登录
  def create
    # 登录用户
    result = log_in_user(params[:session][:email], params[:session][:password])
    # 登录成功
    if result[:success]
      redirect_to result[:user], notice: '登录成功！'
    else
      # 登录失败
      flash.now[:alert] = result[:message]
      render :new
    end
  end

  # DELETE /logout
  # 登出
  def destroy
    # 登出用户信息
    log_out

    # 重定向到登录页面并显示成功消息
    redirect_to login_path, notice: '您已成功退出登录'
  end
end
